import TaskStep from '@/components/taskStep.vue';
import apiMixin from '@/mixin/apiMixin';
import taskMixin from '@/mixin/taskMixin';

import uilts from '@/utils/index';
export default {
    mixins: [apiMixin,taskMixin],
    data() {
        return {
            tableData: [],
            approvalShow: false,
            listNumsTotal: 0,
            compliteIndex: -1,
            compliteContent: {
                taskSteps: [],
                result: [],
                is_show: true
            },
            isClear: false,
            loading:true,
            filters:{
                value:this.$route.query.status ? this.$route.query.status.split(',').map(Number) : [],
                list:[
                    {text:"全部",value:"all"},
                    {text:"待处理",value:"pending"},
                    {text:"已处理",value:""},
                ]
            },
            /*specBtn: {
                text: '待处理',
                //  all pending
                status: 'pending',
                valuse: ''
            }*/
        };
    },
    mounted() {
        this.getTaskComplaintListApi();
    },
    methods: {
        filterTag(filters) {
            console.log(filters)
            /*
            this.page = 1;
            this.status = filters.status.join(",");
            this.getTaskComplaintListApi();
            */
        },
        handle(index){//点击审批时的逻辑
            let _this = this;
            _this.tableData[index].btnLoad = true;
            setTimeout(function(){
                _this.approvalShow = true;
                _this.tableData[index].btnLoad = false;
            },1500);
        },
        initPar() {
            this.isClear =false;
            this.compliteIndex = 0;
            this.compliteContent = {
                taskSteps: [],
                result: [],
                is_show: true
            };
        },
        changePage(page){
            page = page || 1;
            this.getTaskComplaintListApi(page);
        },
        handleApprovalShow() {
            this.approvalShow = !this.approvalShow;
        },
        openPopWill(ceIndex) {
            this.compliteIndex = ceIndex; 
            this.getTaskComplaintDetailApi();
        },
        getTaskComplaintListApi(page = 1) {
            let _self = this;
            this.comResquest(this.request.getTaskComplaintList,(res)=>{
                let { count,result } = res;
                _self.tableData = result;
                _self.listNumsTotal = count;
            },{
                page: page,
                keyword: this.searchText,
                type: this.searchType,
                load: true,
                order: this.filters.value
            })
        },
        postTaskComplaintDetail() {
            let _self = this;
            let taskId = this.tableData[this.compliteIndex].id;
            let curComplite = uilts.simpleCopy(this.tableData[this.compliteIndex]);
            this.comResquest(this.request.postTaskComplaintDetail,(res)=>{
                _self.$message.success("处理成功");
                curComplite.report_status = 1;
                _self.$set(_self.tableData,_self.compliteIndex,curComplite);
                _self.handleApprovalShow();
                _self.initPar();
            },{
                id: taskId,
                is_show: this.compliteContent.is_show ? 1 : 0,
                is_refund: this.isClear ? 1 : 0,
                load: true
            })
        },
        getTaskComplaintDetailApi() {
            let _self = this;
            let taskId = this.tableData[this.compliteIndex].id;
            this.comResquest(this.request.getTaskComplaintDetail,(res)=>{
                console.log(res);
                _self.handleApprovalShow();
                _self.compliteContent = res;
            },{
                task_id: taskId
            })
        },
        dialogClose() {
            this.approvalShow = false;
            this.compliteIndex = -1;
        }
    },
    components: {
        TaskStep
    },
}